﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MaymuseMS.Models;
using MaymuseMS.Models.ValueObject;

namespace MaymuseMS.DAL {
    public class PartsDepositoryRepository : GenericRepository<PartsDepository> {
        public PartsDepositoryRepository(MaymuseMSContext context)
            : base(context) {

        }

        //public void Increase(ProductValueObject productValueObject, int count, string location, string number) {
        //    if (count < 1 || string.IsNullOrWhiteSpace(number)) {
        //        throw new ArgumentNullException("参数不能为空！");
        //    }
        //    var partsDepository = Get(productValueObject.Number);
        //    if (partsDepository == null) {
        //        partsDepository = new PartsDepository {
        //            ProductValueObject = productValueObject
        //        };
        //        this.Add(partsDepository);
        //    } else {
        //        partsDepository.DepositoryItems.Add(new DepositoryItem {
        //            Number = number, Location = location, Count = count
        //        });
        //    }
        //}
        
        //public void Reduce(int id, int count) {
        //    var partsDepository = Get(id);
        //    if (partsDepository != null) {
        //        var depositoryItem = partsDepository.DepositoryItems.Where(d => d.Number == number);
        //        if (depositoryItem != null) {

        //        }
        //    }
        //}

        public PartsDepository Get(string number) {
            var partsDepository = this.dbSet.Where(p => p.ProductValueObject.Number == number).FirstOrDefault();
            return partsDepository;
        }
    }
}